package com.ctsi.organise.event.listener;

import com.ctsi.auth.vcc.manager.UserAccountLockService;
import com.ctsi.framework.organise.security.SecurityUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component;

/**
 * @author zhangjw
 * @className AuthenticationSuccessEventListener
 * @description TODO
 * @date 2019/2/27 15:47
 **/
@Component
public class AuthenticationSuccessEventListener implements ApplicationListener<AuthenticationSuccessEvent> {

    private static final Logger logger = LoggerFactory.getLogger(AuthenticationSuccessEventListener.class);

    @Autowired
    private UserAccountLockService userAccountLockService;

    @Override
    public void onApplicationEvent(AuthenticationSuccessEvent event) {
        SecurityUser user = (SecurityUser) event.getAuthentication().getPrincipal();
       String userName = user.getUsername();
       userAccountLockService.removeLock(userName);
    }
}
